const Koa = require('koa')
const koaBody = require('koa-body')
const userRouter = require('../router/user.route')
const articleRouter = require('../router/article.route')
const questionRouter = require('../router/question.route')
const app = new Koa()

app.use(async (ctx, next) => {
    ctx.set('Access-Control-Allow-Origin', '*');
    ctx.set('Access-Control-Allow-Headers', 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With , ACCESS_TOKEN');
    ctx.set('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE, OPTIONS');
    if (ctx.method == 'OPTIONS') {
        ctx.body = 200;
    } else {
        await next();
    }
})
app.use(koaBody())
app.use(userRouter.routes())
app.use(articleRouter.routes())
app.use(questionRouter.routes())

module.exports = app